﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.Timers;
using System.Windows.Forms;
using 龙裔之争.KG;

namespace 龙裔之争.Game
	{
	public partial class MainFrame : Form
		{
		DateTime DT=DateTime.Now;
		Entrance EN;
		GameData GD;
		List<System.Timers.Timer> timer=new List<System.Timers.Timer>();
		public MainFrame(Entrance EN,GameData GD)
			{
			this.EN = EN;
			this.GD = GD;
			Control.CheckForIllegalCrossThreadCalls = false;
			InitializeComponent();
			}

		private void MainFrame_Load(object sender, EventArgs e)
			{
			//----------显示--------------
			HP.Text = GD.EI.HP.ToString();
			MONEY.Text = GD.GI.money.ToString();
			//----------创建Timer--------------
			this.timer.Add(new System.Timers.Timer());
			this.timer.Add(new System.Timers.Timer());
			this.timer[0].Elapsed += new ElapsedEventHandler(plusATER);
			this.timer[1].Elapsed += new ElapsedEventHandler(plusHPER);
			this.timer[0].Interval = (1 / Math.Sqrt(GD.AI.LSpeed) + 0.2) *1000;
			this.timer[1].Interval = (1 / GD.AI.hper.Speed) * 1000;
			this.timer[0].Enabled = true;
			if (GD.AI.hper.Count == 0)
				{
				this.timer[1].Enabled = false;
				}
			else
				{
				this.timer[1].Enabled = true;
				}
			//--------------------------------
			}
		private void plusATER(object source, System.Timers.ElapsedEventArgs e)
			{
			GD.GI.money += Math.Sqrt(GD.AI.LDamage * 400) + 5;
			GD.EI.HP	-= Math.Sqrt(GD.AI.LDamage * 400) + 5;
			//----------显示--------------
			HP.Text = GD.EI.HP.ToString();
			MONEY.Text = GD.GI.money.ToString();
			}
		private void plusHPER(object source, System.Timers.ElapsedEventArgs e)
			{
            
			}
		private void MainFrame_FormClosed(object sender, FormClosedEventArgs e)
			{
            Application.Exit();
            }

		private void button1_Click(object sender, EventArgs e)
			{
            //（攻击力*0.8+攻速*0.8+50）1.5
            double mon = Math.Round((Math.Sqrt(GD.AI.LDamage * 400) + 5 * 4.9 + Math.Sqrt(GD.AI.LSpeed) + 0.2) * 120) * 1.5 + 50);
            if (GD.GI.money > mon)
            {
                GD.GI.money -= mon;
                GD.AI.LDamage += 1;
                HP.Text = GD.EI.HP.ToString();
                MONEY.Text = GD.GI.money.ToString();
                HELP.Text = "升级成功！";
            }else
            {
                HELP.Text = "升级失败！您的金钱不够!";
            }

            
        }

		private void button2_Click(object sender, EventArgs e)
			{
            //（攻击力*0.8+攻速*0.8+50）1.2
            double mon = Math.Round((Math.Sqrt(GD.AI.LDamage * 400) + 5 * 4.5 + Math.Sqrt(GD.AI.LSpeed) * 50) * 1.4 + 40);
            if (GD.GI.money > mon)
            {
                GD.GI.money -= mon;
				GD.AI.LSpeed += 1;
                //GD.AI.Speed += 0.02;
                //GD.AI.Speed *= 1000;
                //GD.AI.Speed = Math.Round(GD.AI.Speed);
                //GD.AI.Speed /= 1000;
                this.timer[0].Interval = (1 / GD.AI.Speed) * 1000;

                HP.Text = GD.EI.HP.ToString();
                MONEY.Text = GD.GI.money.ToString();

                HELP.Text = "升级成功！";
            }
            else
            {
                HELP.Text = "升级失败！您的金钱不够!";
            }
            
        }

        private void HP_MouseEnter(object sender, EventArgs e)
        {
            HELP.Text = "这是龙的血量\n\r当前恶龙还剩 "+GD.EI.HP+" 滴血";
        }

        private void HP_MouseLeave(object sender, EventArgs e)
        {
            HELP.Text = "";
        }

        private void label1_MouseEnter(object sender, EventArgs e)
        {
            HELP.Text = "这是龙的血量\n\r当前恶龙还剩 " + GD.EI.HP + " 滴血";
        }

        private void label1_MouseLeave(object sender, EventArgs e)
        {
            HELP.Text = "";
        }

        private void MONEY_MouseEnter(object sender, EventArgs e)
        {
            HELP.Text = "这是你当前的金钱持有数\n\r当前你持有 "+GD.GI.money+" 块钱";
        }

        private void MONEY_MouseLeave(object sender, EventArgs e)
        {
            HELP.Text = "";
        }

        private void label2_MouseEnter(object sender, EventArgs e)
        {
            HELP.Text = "这是你当前的金钱持有数\n\r当前你持有 " + GD.GI.money + " 块钱";
        }

        private void label2_MouseLeave(object sender, EventArgs e)
        {
            HELP.Text = "";
        }

        private void Hero_MouseEnter(object sender, EventArgs e)
        {
            HELP.Text = "这是我们伟大的英雄\n\r当前他的攻击力为	" + GD.AI.Damage + "\n\r当前他的攻速为	" + GD.AI.Speed+"　次/秒";
        }

        private void Hero_MouseLeave(object sender, EventArgs e)
        {
            HELP.Text = "";
        }

        private void button1_MouseEnter(object sender, EventArgs e)
        {
            HELP.Text = "在这能以金钱为代价提升勇者的攻击力\n\r下一次升级需要 "+
                Math.Round((GD.AI.Damage * 4.9 + GD.AI.Speed * 120) * 1.5 + 50) +
                " 元\n\r可使勇者的攻击力 +1";
        }

        private void button1_MouseLeave(object sender, EventArgs e)
        {
            HELP.Text = "";
        }

        private void button2_MouseEnter(object sender, EventArgs e)
        {
            HELP.Text = "在这能以金钱为代价提升勇者的攻速\n\r下一次升级需要 "+
                 Math.Round((GD.AI.Damage * 4.5 + GD.AI.Speed * 50) * 1.4 + 40) +
                 " 元\n\r可使勇者的攻速 +0.02 秒/次";
        }

        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            HELP.Text = "频频袭击人类的恶龙\n\r它真名好像叫奥杜因";
        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            HELP.Text = "";
        }
    }
}
